package com.gym.web.controller.statistics.controller;

import com.gym.common.annotation.Log;
import com.gym.common.core.controller.BaseController;
import com.gym.common.core.domain.AjaxResult;
import com.gym.common.core.page.TableDataInfo;
import com.gym.common.enums.BusinessType;
import com.gym.common.utils.poi.ExcelUtil;
import com.gym.system.statistics.domain.GymGoodsStatistics;
import com.gym.system.statistics.service.IGymGoodsStatisticsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 统计Controller
 *
 * @author administrator
 * @date 2021-04-11
 */
@Controller
@RequestMapping("/statistics/statistics")
public class GymGoodsStatisticsController extends BaseController {
    private String prefix = "statistics/statistics";

    @Autowired
    private IGymGoodsStatisticsService gymGoodsStatisticsService;

    @RequiresPermissions("statistics:statistics:view")
    @GetMapping()
    public String statistics() {
        return prefix + "/statistics";
    }

    /**
     * 查询统计列表
     */
    @RequiresPermissions("statistics:statistics:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GymGoodsStatistics gymGoodsStatistics) {
        startPage();
        List<GymGoodsStatistics> list = gymGoodsStatisticsService.selectGymGoodsStatisticsList(gymGoodsStatistics);
        return getDataTable(list);
    }

    /**
     * 导出统计列表
     */
    @RequiresPermissions("statistics:statistics:export")
    @Log(title = "统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GymGoodsStatistics gymGoodsStatistics) {
        List<GymGoodsStatistics> list = gymGoodsStatisticsService.selectGymGoodsStatisticsList(gymGoodsStatistics);
        ExcelUtil<GymGoodsStatistics> util = new ExcelUtil<GymGoodsStatistics>(GymGoodsStatistics.class);
        return util.exportExcel(list, "statistics");
    }

    /**
     * 新增统计
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存统计
     */
    @RequiresPermissions("statistics:statistics:add")
    @Log(title = "统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GymGoodsStatistics gymGoodsStatistics) {
        return toAjax(gymGoodsStatisticsService.insertGymGoodsStatistics(gymGoodsStatistics));
    }

    /**
     * 修改统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        GymGoodsStatistics gymGoodsStatistics = gymGoodsStatisticsService.selectGymGoodsStatisticsById(id);
        mmap.put("gymGoodsStatistics", gymGoodsStatistics);
        return prefix + "/edit";
    }

    /**
     * 修改保存统计
     */
    @RequiresPermissions("statistics:statistics:edit")
    @Log(title = "统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GymGoodsStatistics gymGoodsStatistics) {
        return toAjax(gymGoodsStatisticsService.updateGymGoodsStatistics(gymGoodsStatistics));
    }

    /**
     * 删除统计
     */
    @RequiresPermissions("statistics:statistics:remove")
    @Log(title = "统计", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(gymGoodsStatisticsService.deleteGymGoodsStatisticsByIds(ids));
    }
}
